package jnpf.file;

import jnpf.file.fallback.FileUploadApiFallback;
import cn.xuyanwu.spring.file.storage.FileInfo;
import jnpf.model.FileListVO;
import jnpf.model.MinioCopyObjectModel;
import jnpf.model.upload.UploadFileModel;
import jnpf.utils.FeignName;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 文件上传API
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * @date 2021-07-23
 */
@FeignClient(name = FeignName.FILE_SERVER_NAME, fallback = FileUploadApiFallback.class, path = "/upload")
public interface FileUploadApi {
    /**
     * 文件上传
     *
     * @param multipartFile
     * @param folderName
     * @param fileName
     * @return
     */
    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    FileInfo uploadFile(@RequestPart("multipartFile") MultipartFile multipartFile, @RequestParam("folderName") String folderName, @RequestParam("fileName") String fileName);


    /**
     * 文件上传
     *
     * @param multipartFile
     * @param folderName
     * @param type
     * @param fileName
     * @return
     */
    @PostMapping(value = "/uploadFiles", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    FileInfo uploadFile(@RequestPart("multipartFile") MultipartFile multipartFile, @RequestParam("folderName") String folderName, @RequestParam("type") String type,@RequestParam("fileName") String fileName);


    /**
     * 拷贝文件到其他Minio下
     *
     * @param model
     */
    @PostMapping("/copyObject")
    void copyObject(@RequestBody MinioCopyObjectModel model);

    @GetMapping(value = "/getByte/{fileName}/{folderName}")
    byte[] getByte(@PathVariable("fileName") String fileName, @PathVariable("folderName") String folderName);

    /**
     * 获取存储桶下文件夹中的内容
     *
     * @param folderName    存储桶名
     * @return
     */
    @GetMapping(value = "/getByte")
    List<FileListVO> getFileList(@RequestParam("folderName") String folderName);


    @PostMapping("/downToLocal")
    void downToLocal(@RequestBody UploadFileModel model);

    @PostMapping("/downFile")
    void downFile(@RequestBody UploadFileModel model);

    @PostMapping("/downFileByte")
    byte[] downFileByte(@RequestBody UploadFileModel model);

    @GetMapping("/getFile/{fileId}")
    FileInfo getFile(@PathVariable("fileId") String fileId);
}
